<?PHP
class buy
{
	var $input;
	var $data;
	var $output;
	function co_confirm($post,$session)
	{
			
		$go=0;
		if($_POST['cart_id']==$_SESSION['transid'])
		{
				
				$go=1;
		}
		else
		{
			$errors[]='There was a problem with your order, YOUR CREDIT CARD WAS NOT BILLED, please try again';
			return false;
		}
		
		if($_POST['credit_card_processed']=='Y')
		{
					
					$go=2;
		}
		else
		{
			$errors[]='There was a problem with your order, YOUR CREDIT CARD WAS NOT BILLED, please try again';
			return false;
		}

		if($go==2)
		{
			$string_to_hash = $conf->a['2co-secret'].$conf->a['2co-sid'].$_POST['order_number'].$_POST['total'];
			$secretmd5=md5($string_to_hash);
		//	echo $secretmd5;
			$go=3;
		}
		$xv=false;
		
			$xv=true;
		
		
		if($secretmd5==$_POST['key'] && $go==3 || $xv)
		{
			return true;
		}
		else
		{
			$errors[]='There was a problem with your order, please contact billing@pinoytuner.com';
			return false;
		}
	
	}
	
	function clean_transaction_id()
	{
		
	}
	function process_paypal()
	{
		global $conf;
		$transaction_id=str_replace($conf->a['cc-prehash']."-", "", $_SESSION['transid']);
		$user=new user();
		$user->post=$_SESSION['user_data'];
	
		//record transaction
		// 
		// 
		$access=new content_access;
		$conf->style['masthead'].=": Thank You";
		//give access
		$access->input['content']=$_SESSION['content'];
		$access->input['transaction']=$transaction_id;

		$access->mode='silent';
		$access->where['content']=$_SESSION['content'];
		$access->check_token();
		
		if($_SESSION['user_level']==0)
		{
			$buy='new';
			//echo 'bago';
			//echo $_SESSION['user_data']['user_email'];
			//	$user->add_user_confirmed();
			$access->input['user_email']=$_SESSION['user_data']['user_email'];
			$user->add_user_confirmed();
		}
		else
		{
			$access->input['user_email']=$_SESSION['user_email'];
		}
	//	print_r($content['access_end_type']);
		
		
		$access->grant_token();
		$transaction['transaction']=$_SESSION['resArray']['PAYMENTINFO_0_TRANSACTIONID'];
		$transaction['content']=$this->input['id'];
		$transaction['serial']=serialize($_SESSION['resArray']);
		$transaction['payment_method']=$_SESSION['payment_method'];
		$transaction['payment_time']=$_SESSION['resArray']['TIMESTAMP'];
		$transaction['hash']=$transaction_id;
		$transaction['email']=$access->input['user_email'];
		$transaction['status']=$_SESSION['resArray']['PAYMENTINFO_0_PAYMENTSTATUS'];
		$transaction['amount']=$_SESSION["Payment_Amount"];
		$transaction['sandbox']=$conf->a['purchase-sandbox'];
		process_sql_post($transaction,'transaction','add','id');
	}
	
	
	function process_2co()
	{
		global $conf;
		//$prehash=$conf->a['cc-prehash'];
		$transaction_id=str_replace($conf->a['cc-prehash']."-", "", $_SESSION['transid']);
		$user=new user();
		$user->post=$_SESSION['user_data'];
	
		//record transaction
		// 
		// 
		$access=new content_access;
		$conf->style['masthead'].=": Thank You";
		//give access
		$access->input['content']=$_SESSION['content'];
		$access->input['transaction']=$transaction_id;

		$access->mode='silent';
		$access->where['content']=$_SESSION['content'];
		$access->check_token();
		
		if($_SESSION['user_level']==0)
		{
			$buy='new';
	
			$access->input['user_email']=$_SESSION['user_data']['user_email'];
			$user->add_user_confirmed();
		}
		else
		{
			$access->input['user_email']=$_SESSION['user_email'];
		}

//	print_r($this->input['transaction_details']);	
		$access->grant_token();
		$transaction['transaction']=$this->input['transaction_details']['order_number'];
		$transaction['content']=$this->input['id'];
		$transaction['serial']=serialize($this->input['transaction_details']);
		$transaction['payment_method']=$_SESSION['payment_method'];
		$transaction['payment_time']=$this->input['transaction_details']['order_number'];
		$transaction['hash']=$transaction_id;
		$transaction['email']=$access->input['user_email'];
		$transaction['content']=$_SESSION['content'];
		$transaction['status']='Completed';
		$transaction['amount']=$_SESSION["Payment_Amount"];
		$transaction['sandbox']=$conf->a['purchase-sandbox'];
		process_sql_post($transaction,'transaction','add','id');
	}
	
	function process_purchase()
	{
		
	}
}
?>